import threading

import requests

auto_edit_n2_web_url = 'http://172.16.241.109:8080/view/%E5%A4%A7%E8%B1%A1%E7%9B%B8%E4%BC%BC%E5%9B%BE%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8F%91%E5%B8%83/job/auto_edit_n2_update/build?token=auto_edit_n2_deploy'
auto_edit_n2_tencent_url = 'http://172.16.241.109:8080/view/%E8%85%BE%E8%AE%AF%E7%89%88%E6%9D%83%E6%9B%B4%E6%96%B0/job/txbq_auto_edit_n2_update/build?token=txbq_auto_edit_n2_deploy'


# 连接jenkins
def connect_genkins_edit(url):
	# 重定向以后的登录验证url
	headers = {
		'user-agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
	}
	login_url = 'http://172.16.241.109:8080/j_acegi_security_check'
	data = {
		'j_username': 'wenxiangpeng',
		'j_password': 'qw*&Bao2'
	}
	# 建立会话
	s = requests.session()
	r = s.post(url=login_url, data=data, headers=headers)

	# 任务url
	# auto_edit_n2_deploy_url = 'http://172.16.241.109:8080/view/%E5%A4%A7%E8%B1%A1%E7%9B%B8%E4%BC%BC%E5%9B%BE%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8F%91%E5%B8%83/job/auto_edit_n2_update/build?token=auto_edit_n2_deploy'
	# headers = {
	# 	'Referer': 'http://39.106.177.73:8080/login?from=%2F'
	# }
	response = s.get(url=url, headers=headers)
	print(response.status_code)


th1 = threading.Thread(target=connect_genkins_edit, args=(auto_edit_n2_web_url,))  # 生成一个线程实例
th2 = threading.Thread(target=connect_genkins_edit, args=(auto_edit_n2_tencent_url,))  # 生成另一个线程实例

th1.start()
th2.start()
print(th1.getName())
print(th2.getName())
th1.join()
th2.join()